#!/bin/bash
# $Description:  Monitor Memcached Service Status
M_PORT=11211
M_COMMAND=$1
m_status_fun(){
	echo -e "stats\nquit" | nc 127.0.0.1 "$M_PORT" | grep "STAT $M_COMMAND " | awk '{print $3}'
}

case $M_COMMAND in
	accepting_conns)
		m_status_fun "$M_PORT" "accepting_conns"
		;;
	auth_cmds)
		m_status_fun "$M_PORT" "auth_cmds"
		;;
	auth_errors)
		m_status_fun "$M_PORT" "auth_errors"
		;;
	bytes)
		m_status_fun "$M_PORT" "bytes"
		;;
	bytes_read)
		m_status_fun "$M_PORT" "bytes_read"
		;;
	bytes_written)
		m_status_fun "$M_PORT" "bytes_written"
		;;
	cas_badval)
		m_status_fun "$M_PORT" "cas_badval"
		;;
	cas_hits)
		m_status_fun "$M_PORT" "cas_hits"
		;;
	cas_misses)
		m_status_fun "$M_PORT" "cas_misses"
		;;
	cmd_flush)
		m_status_fun "$M_PORT" "cmd_flush"
		;;
	cmd_get)
		m_status_fun "$M_PORT" "cmd_get"
		;;
	cmd_set)
		m_status_fun "$M_PORT" "cmd_set"
		;;
	connection_structures)
		m_status_fun "$M_PORT" "connection_structures"
		;;
	conn_yields)
		m_status_fun "$M_PORT" "conn_rields"
		;;
	curr_items)
		m_status_fun "$M_PORT" "curr_items"
		;;
	curr_connections)
		m_status_fun "$M_PORT" "curr_connections"
		;;
	decr_hits)
		m_status_fun "$M_PORT" "decr_hits"
		;;
	decr_misses)
		m_status_fun "$M_PORT" "decr_misses"
		;;
	delete_hits)
		m_status_fun "$M_PORT" "delete_hits"
		;;
	delete_misses)
		m_status_fun "$M_PORT" "delete_misses"
		;;
	evictions)
		m_status_fun "$M_PORT" "evictions"
		;;
	get_hits)
		m_status_fun "$M_PORT" "get_hits"
		;;
	get_misses)
		m_status_fun "$M_PORT" "get_misses"
		;;
	incr_hits)
		m_status_fun "$M_PORT" "incr_hits"
		;;
	incr_misses)
		m_status_fun "$M_PORT" "incr_misses"
		;;		
	limit_maxbytes)
		m_status_fun "$M_PORT" "limit_maxbytes"
		;;
	listen_disabled_num)
		m_status_fun "$M_PORT" "listen_disabled_num"
		;;
	pid)
		m_status_fun "$M_PORT" "pid"
		;;
	pointer_size)
		m_status_fun "$M_PORT" "pointer_size"
		;;
	reclaimed)
		m_status_fun "$M_PORT" "reclaimed"
		;;
	rusage_user)
		m_status_fun "$M_PORT" "rusage_user"
		;;
	threads)
		m_status_fun "$M_PORT" "threads"
		;;
	time)
		m_status_fun "$M_PORT" "time"
		;;
	total_items)
		m_status_fun "$M_PORT" "total_items"
		;;
	total_connections)
		m_status_fun "$M_PORT" "total_connections"
		;;
	uptime)
		m_status_fun "$M_PORT" "uptime"
		;;
	version)
		m_status_fun "$M_PORT" "version"
		;;
	*)
		echo "inpurt error"
esac	

